#Maintainer: Ma, Leon <akml@163.com>

_realname=global
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.5.2
pkgrel=1
pkgdesc="GNU GLOBAL source code tagging system (mingw-w64)"
arch=('any')
url='https://www.gnu.org/software/global'
license=('GPL3')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-ncurses")

source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"
        'glo652.txt' #Jason Hood <jadoxa@yahoo.com.au>, http://adoxa.altervista.org/global
        '002-fix-sigset_t-undefined.txt')
sha256sums=('c0fc831c1a54a5ee4f5fc765a7af90ade773e4fb4763416c0b6d4d2e571b1d1f'
            '82d0c653d120417f89fd5b485bdaf974d3bf20924e4ca082b18c87b0d07cfcd7'
            '06e2d891f174f93187b754c149f48bbed01c5719d693439197f00ea8a2e8fe29')

_global_srcdir=${_realname}-${pkgver}

prepare() {
  cd ${_global_srcdir}
  patch -p1 -i ${srcdir}/glo652.txt

  patch -p1 -i ${srcdir}/002-fix-sigset_t-undefined.txt

  rm -rf "${srcdir}"/build-${CARCH}
}

build() {
  cd ${srcdir} && mkdir build-${CARCH} && cd build-${CARCH}
  export CPPFLAGS="-I${MINGW_PREFIX}/include/ncurses"

  ../${_global_srcdir}/configure \
    --prefix=${MINGW_PREFIX}

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
